import { ElNotification,ElMessage  } from 'element-plus'
import nprogress from 'nprogress'

// 侧边消息提示
export function toast(message:any,type:'success' | 'warning' | 'info' | 'error' | '' = "success",dangerouslyUseHTMLString = true){
  ElNotification({
      message,
      type,
      dangerouslyUseHTMLString, //是否将 message 属性作为 HTML 片段处理
      duration:3000
  })
}
// 顶部消息提示
export function Message(message:any,type:'success' | 'warning' | 'info' | 'error' = "success",dangerouslyUseHTMLString = true){
  ElMessage({
      message,
      type,
      dangerouslyUseHTMLString, //是否将 message 属性作为 HTML 片段处理
      duration:3000
  })
}

// 显示全屏loading
export function showFullLoading() {
  console.log('开始')
  nprogress.start()
}

// 隐藏全屏loading
export function hideFullLoading() {
  console.log('结束')
  
  nprogress.done()
}



// 将query对象转成url参数
export function queryParams(query:any){
  let q = []
  for (const key in query) {
      if(query[key]){
          q.push(`${key}=${encodeURIComponent(query[key])}`)
      }
  }
  let r = q.join("&")
  r = r ? ("?"+r) : ""
  return r
}

// 上移
export function useArrayMoveUp(arr:any,index:number){
  swapArray(arr,index,index - 1)
}

// 下移
export function useArrayMoveDown(arr:any,index:number){
  swapArray(arr,index,index + 1)
}

function swapArray(arr:any,index1:number,index2:number){
  arr[index1] = arr.splice(index2,1,arr[index1])[0]
  return arr
}


